package com.libertyville.domain.orgmng.validator;

import com.libertyville.domain.orgmng.OrgTypeRepository;
import com.libertyville.domain.orgmng.OrgTypeStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrgTypeValidator {
    private OrgTypeRepository orgTypeRepository;

    @Autowired
    public OrgTypeValidator(OrgTypeRepository orgTypeRepository) {
        this.orgTypeRepository = orgTypeRepository;
    }

    public void validateOrgType(Integer tenantId, String orgTypeCode) {
        if (!orgTypeRepository.existsByIdAndOrgTypeCodeAndStatus(tenantId, orgTypeCode, OrgTypeStatus.EFFECTIVE))
            throw new RuntimeException("Failed to create Org because Org Type Code " + orgTypeCode + " is not valid");
    }
}
